function forwardSmoothed = smoothingFct( forward, mats, smoother )

if isempty(smoother)
    forwardSmoothed=forward;
    return
end

bw=smoother.bw; %bandwidth
kernel=smoother.kernel;

[T, N]=size(forward);

forwardSmoothed=NaN(T,N);
for j=1:N

    for t=1:T
   
    select = ~isnan(forward(t,:));  
    z=(mats(select,1)-mats(j,1))/bw;
    
        if kernel==1 %uniform (equal weighted to both sides)

        tmp = 1/2*(abs(z)<=1);

        elseif kernel==2 %weights based on Gaussian kernel
        
        tmp = (2*pi)^(-1/2)*exp(-(z.^2)/2);
        
        elseif kernel==3 %weights based on Epanechnikov kernel
            
        tmp = 3/4*(1-(z.^2)).*(abs(z)<=1);           
        
        end
        w_j=tmp/sum(tmp);
        
        if ~isnan(forward(t,j));
        forwardSmoothed(t,j)=forward(t,select)*w_j;       
        else
        forwardSmoothed(t,j)=NaN;
        end

    end
    
end